Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up logging for next major #1070

Merged
merged 1 commit into from
Apr 17, 2020

Conversation

brandur
Copy link
Contributor

@brandur brandur commented Apr 16, 2020

Background

For a very long time, stripe-go logged by way of the Printfer
interface:

type Printfer interface {
       Printf(format string, v ...interface{})
}

Printfer had a few problems: it didn't allow any kind of granularity
around logging levels, didn't allow us to behave well by sending errors
to stderr and other output to stdout, and wasn't interoperable with
any popular Go loggers (it was interoperable with the one in the
stdlib's log, but serious programs tend to move away from that).

A while back, I introduced the new LeveledLogger interface, which
corrected the deficiencies with Printfer.

We made quite a bit of effort to stay compatible with the existing
configuration options around logging like the Logger and LogLevel
globals, while also adding new ones for the leveled logger like
DefaultLeveledLogger.

The downside of that is it made reasoning about the different
combinations complicated. For example, you had to know that if both
Logger and DefaultLeveledLogger were set, then the former would take
precedence, which isn't necessarily obvious.

Changes in this patch

Since we're on the verge of a major, I've taken the liberty of cleaning
up all the old logging infrastructure. This involves removing its types,
interfaces, helpers, global configuration options, and local
configuration options. We're left with a much simpler setup with just
stripe.DefaultLeveledLogger and BackendConfig.LeveledLogger.

Users who were already using the leveled logger (as recommended in the
README for sometime) won't have to change anything, nor will users who
had no logging configured. Users on the old infrastructure will have to
make some config tweaks, but ones that are quite easy.

And since we're changing logging things anyway: I've made a small tweak
such that if left unset by the user, the default logger now logs errors
only (instead of errors + informational). This is a more reasonable
default on Unix systems where programs are generally not expected to be
noisy over stdout. If a user wants to get informational messages back,
it's a very easy configuration tweak to DefaultLeveledLogger. I think
this change is okay for the reason above, but also because I don't think
a lot of thought was ever put into the original default -- we've just
been cargo culting through releases for a long time now.

r? @ob-stripe @remi-stripe
cc @stripe/api-libraries


Note: Targets the branch in #1055 for V71 integration.

 ## Background

For a very long time, stripe-go logged by way of the `Printfer`
interface:

``` go
type Printfer interface {
       Printf(format string, v ...interface{})
}
```

`Printfer` had a few problems: it didn't allow any kind of granularity
around logging levels, didn't allow us to behave well by sending errors
to `stderr` and other output to `stdout`, and wasn't interoperable with
any popular Go loggers (it was interoperable with the one in the
stdlib's `log`, but serious programs tend to move away from that).

A while back, I introduced the new `LeveledLogger` interface, which
corrected the deficiencies with `Printfer`.

We made quite a bit of effort to stay compatible with the existing
configuration options around logging like the `Logger` and `LogLevel`
globals, while also adding new ones for the leveled logger like
`DefaultLeveledLogger`.

The downside of that is it made reasoning about the different
combinations complicated. For example, you had to know that if both
`Logger` and `DefaultLeveledLogger` were set, then the former would take
precedence, which isn't necessarily obvious.

 ## Changes in this patch

Since we're on the verge of a major, I've taken the liberty of cleaning
up all the old logging infrastructure. This involves removing its types,
interfaces, helpers, global configuration options, and local
configuration options. We're left with a much simpler setup with just
`stripe.DefaultLeveledLogger` and `BackendConfig.LeveledLogger`.

Users who were already using the leveled logger (as recommended in the
README for sometime) won't have to change anything, nor will users who
had no logging configured. Users on the old infrastructure will have to
make some config tweaks, but ones that are quite easy.

And since we're changing logging things anyway: I've made a small tweak
such that if left unset by the user, the default logger now logs errors
only (instead of errors + informational). This is a more reasonable
default on Unix systems where programs are generally not expected to be
noisy over stdout. If a user wants to get informational messages back,
it's a very easy configuration tweak to `DefaultLeveledLogger`.
@brandur brandur mentioned this pull request Apr 16, 2020
7 tasks
@brandur-stripe brandur-stripe changed the base branch from brandur-default-2-retries to integration-v71 April 16, 2020 22:37
@brandur-stripe
Copy link
Contributor

Thank you Richard!

@brandur-stripe brandur-stripe merged commit 4769892 into integration-v71 Apr 17, 2020
@brandur-stripe brandur-stripe deleted the brandur-logging-cleanup branch April 17, 2020 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants